window.addEventListener("load",()=>{
    // let xhr = new XMLHttpRequest
    // xhr.open("get","172.18.214.70:8080/login",true)
    // xhr.onreadystatechange=function(){
    //     if(xhr.status===200 && xhr.readystate===4){
    //         console.log(xhr.responseText)
    //     }
    // }
    // xhr.send()


    // 1. 使用Promise模拟一个异步操作
    function simulateAsyncTask(shouldSucced=true){
        return new Promise((resolve,reject)=>{
            setTimeout(()=>{
                if (shouldSucced){
                    resolve("异步任务成功完成！");
                }
                else{
                     reject("异步任务失败了！");
                }
            },1000)
        })
    }
    // 2. 使用Fetch API获取数据
     function fetchUserData() {
            let output = document.getElementById('output');
            let statusArea = document.getElementById('statusArea');
        // 清空状态区域
            statusArea.innerHTML = '';
               // 显示加载状态
            let loadingDiv = document.createElement('div');
            loadingDiv.className = 'status loading';
            loadingDiv.innerHTML = '🔄 正在加载数据...';
    
            // 模拟异步操作
          simulateAsyncTask()
                .then(data => {
                    output.textContent = data;
                    const successDiv = document.createElement('div');
                    successDiv.className = 'status success';
                    successDiv.textContent = '✅ 数据加载成功';
                    statusArea.appendChild(successDiv);
                })
                .catch(error => {
                    output.textContent = error;
                    const errorDiv = document.createElement('div');
                    errorDiv.className = 'status error';
                    errorDiv.textContent = '❌ 数据加载失败: ' + error;
                    statusArea.appendChild(errorDiv);
                });
        }
})